#define UP    1
#define DOWN  2
#define LEFT  3
#define RIGHT 4 //蛇的状态，上下左右

int direction = RIGHT;//蛇的初始移动方向

//移动贪食蛇
void movesnake(){
    int left,top,right,bottom;
	int newleft,newtop,newright,newbottom;

	snake *p;//蛇遍历指针

	//擦除蛇尾巴
	setcolor(WHITE);setfillcolor(GREEN);
	fillrectangle(tail->left,tail->top,tail->right,tail->bottom);

	//从头到尾输出蛇身新位置
	p = head;
	while(p != NULL){
		Sleep(100);

		if(p == head){//如果是蛇头，就移动到新的位置
			//保存蛇头原始坐标
			newleft   = p->left;
			newtop    = p->top;
			newright  = p->right;
			newbottom = p->bottom;

			//蛇头使用下一个位置坐标
			if(direction == RIGHT){//向右下一个位置
				p->left += 20;
				p->right += 20;
			}
			if(direction == LEFT){//向左下一个位置
				p->left -= 20;
				p->right -= 20;
			}
			if(direction == UP){//向上下一个位置
				p->top -= 20;
				p->bottom -= 20;
			}
			if(direction == DOWN){//向下下一个位置
				p->top += 20;
				p->bottom += 20;
			}

			else{//其他节点使用上一个节点的位置
				//保存当前蛇身体坐标
				left = p->left;
				top = p->top;
				right = p->right;
				bottom = p->bottom;

				//将蛇身体当前节坐标变换成蛇的上一节坐标
				p->left = newleft;
				p->top = newtop;
				p->right = newright;
				p->bottom = newbottom;

				newleft = left;
				newtop = top;
				newright = right;
				newbottom = bottom;
			}

			//绘制蛇的当前节
			setcolor(white);
			setfillcolor(RED);

			fillrectangle(p->left,p->top,p->right,p->bottom);
			
			if(p == head){//如果是蛇头，画个圆当眼睛
				fillrectangle(newleft,newtop,newright,newbottom);//擦除原来的蛇头
				int x = (p->left)
			}
		}
	}
}